package com.cloudfun.campusshare.configuration.jpa.util;

import java.io.Serializable;

/**
 * @author 王溪源
 * @ClassName: PropertyFilter
 * @Description: TODO
 * @Date 2020/8/7 18:13
 **/
public class PropertyFilter implements Serializable {
    // 约束名称
    private String restrictionName;

    // 属性类型
    private Class<?> propertyType;

    // 属性名称
    private String[] propertyNames;

    // 对比值
    private String matchValue;

    public PropertyFilter(String restrictionName, PropertyType propertyType, String[] propertyNames, String matchValue) {
        this.restrictionName = restrictionName;
        this.propertyType = propertyType.getValue ();
        this.propertyNames = propertyNames;
        this.matchValue = matchValue;
    }

    public String getRestrictionName() {
        return restrictionName;
    }

    public void setRestrictionName(String restrictionName) {
        this.restrictionName = restrictionName;
    }

    public Class<?> getPropertyType() {
        return propertyType;
    }

    public void setPropertyType(Class<?> propertyType) {
        this.propertyType = propertyType;
    }

    public String[] getPropertyNames() {
        return propertyNames;
    }

    public void setPropertyNames(String[] propertyNames) {
        this.propertyNames = propertyNames;
    }

    public String getMatchValue() {
        return matchValue;
    }

    public void setMatchValue(String matchValue) {
        this.matchValue = matchValue;
    }

    /**
     * @param
     * @return boolean
     * @author 王溪源
     * @Description: 是否存在多个属性，如果是 返回true 否则返回false
     * @Date
     */
    public boolean hasMultiplePropertyNames() {
        return this.propertyNames != null && this.propertyNames.length > 1;
    }

    public String getSinglePropertyName() {
        if (hasMultiplePropertyNames ()) {
            throw new IllegalAccessError ("");
        }
        return this.propertyNames[0];
    }
}
